package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author csc
 * @Date 2023/3/11 0011 20:44
 * @Version 1.0
 */
@RestController
public class PaymentController
{
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody  Payment payment){
        int i = paymentService.create(payment);
        if(i>0){
            return new CommonResult(200,"新增成功 serverPort"+serverPort);
        }else{
            return new CommonResult(201,"失败");
        }
    }//end create

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentByid(id);

        if(payment != null){
            return new CommonResult(200,"查询成功哈哈哈 serverPort:"+serverPort,payment);
        }else{
            return new CommonResult(201,"失败");
        }


    }//end getPaymentById

    @GetMapping(value = "/payment/lb")
    public String getPaymentLB(){
        return serverPort;
    }


}
